var prefix = ctx + "manage/withdrawalConfig";

$(function () {
    var options = {
        url: prefix + "/list",
        queryParams: queryParams,
        columns: [
            {
                checkbox: true
            },
            {
                field: 'wcMoney',
                title: '金额'
            },
            {
                field: 'wcNumber',
                title: '提现次数'
            },
            {
                field: 'wsToExamine',
                title: '是否审核',
                formatter: function (value, row, index) {
                    if (value === 1) {
                        return '<span class="badge badge-danger">是</span>';
                    }
                    if (value === 2) {
                        return '<span class="badge badge-success">否</span>';
                    }
                }
            },
            {
                field: 'wcType',
                title: '类型',
                formatter: function (value, row, index) {
                    if (value === 1) {
                        return '<span class="badge badge-warning">金币</span>';
                    }
                    if (value === 2) {
                        return '<span class="badge badge-danger">红包</span>';
                    }
                    if (value === 3) {
                        return '<span class="badge badge-info">金币佣金</span>';
                    }
                    if (value === 4) {
                        return '<span class="badge badge-success">红包佣金</span>';
                    }
                    if (value === 5) {
                        return '<span class="badge badge-primary">推广佣金</span>';
                    }
                }
            },
            {
                field: 'createTime',
                title: '创建时间'
            },
            {
                title: '操作',
                align: 'center',
                formatter: function (value, row, index) {
                    var actions = [];
                    actions.push('<a class="btn btn-primary btn-sm ' + editFlag + '" href="#" title="编辑" mce_href="#" onclick="edit(\'' + row.id + '\')"><i class="fa fa-edit"></i></a> ');
                    actions.push('<a class="btn btn-warning btn-sm ' + removeFlag + '" href="#" title="删除" onclick="remove(\'' + row.id + '\')"><i class="fa fa-remove"></i></a>');
                    return actions.join('');
                }
            }]
    };
    $.ryTable.init(options);
});

/*奖励记录-搜索*/
function search() {
    $('.bootstrap-table').bootstrapTable('refresh', queryParams);
}

function queryParams(params) {
    return {
        // 传递参数查询参数
        pageSize: params.limit,
        pageNum: params.offset / params.limit + 1,
        wsToExamine: $("#wsToExamine option:selected").val(),
        uvChannel:  uvChannel,
        wcType: $("#wcType option:selected").val()
    };
}

/*提现金额配置-新增*/
function add() {
    var url = prefix + '/add/'+ uvChannel;
    layer_showAuto("新增提现金额配置", url);
}

/*提现金额配置-修改*/
function edit(id) {
    var url = prefix + '/edit/' + id;
    layer_showAuto("修改提现金额配置", url);
}

// 单条删除
function remove(id) {
    $.modalConfirm("确定要删除选中提现金额配置吗？", function () {
        _ajax(prefix + "/remove/" + id, "", "post");
    })
}

// 批量删除
function batchRemove() {
    var rows = $.getSelections("id");
    if (rows.length == 0) {
        $.modalMsg("请选择要删除的数据", "warning");
        return;
    }
    $.modalConfirm("确认要删除选中的" + rows.length + "条数据吗?", function () {
        _ajax(prefix + '/batchRemove', {"ids": rows}, "post");
    });
}
